<script setup lang="ts">
    import { defineAsyncComponent,reactive,ref,toRefs } from 'vue';
    import base from "@/utils/base";
    import { uploadImg } from '@/api/common/media';
    import request from "@/utils/request";
    import {notify} from '@/utils/element'
    import { Session } from '@/utils/storage';
    const Editor=defineAsyncComponent(()=>import('@/components/editor/index.vue'));
                                                                                                                                                                                                                                        const formRef=ref();
    const state=reactive({
        loadding:false,//加载框
        visible:false,//隐藏显示
        roisfalg:{
                                                                            weibaoxiangmu: false,
                                                weibaoneirong: false,
                                                weibaozhouqi: false,
                                                weibaodidian: false,
                                                weibaokaishishijian: false,
                                                weibaojieshushijian: false,
                                                fuzeren: false,
                                                lianxifangshi: false,
                                                userid: false,
                               },
        formData:{} as any,

                                                                                                                                                                                                                                                                                                                                                                                                                                                                                title:'新增',
        type:'add',
        id:''
    })
    const initData={

    }
    const {
        loadding,
        visible,
        formData,
        title,
        type,
        id,
        roisfalg
                                                                                                                                                                                                                                                                                                                                                                                                                                                                            } = {...toRefs(state)};


    function open(title:string,id:any,type:string,formData?:any)
    {

        state.title = title;
        state.type = type;
        state.id = id;
        state.formData = {...formData,...initData }
        ;
        state.visible = true;
        if (state.type == 'cross') {
            var obj = Session.get('crossObj');
            for (var o in obj) {
                                                                                                                                    if (o == 'weibaoxiangmu') {
                            state.formData.weibaoxiangmu = obj[o];
                            state.roisfalg.weibaoxiangmu = true;
                            continue;
                        }
                                                                                if (o == 'weibaoneirong') {
                            state.formData.weibaoneirong = obj[o];
                            state.roisfalg.weibaoneirong = true;
                            continue;
                        }
                                                                                if (o == 'weibaozhouqi') {
                            state.formData.weibaozhouqi = obj[o];
                            state.roisfalg.weibaozhouqi = true;
                            continue;
                        }
                                                                                if (o == 'weibaodidian') {
                            state.formData.weibaodidian = obj[o];
                            state.roisfalg.weibaodidian = true;
                            continue;
                        }
                                                                                if (o == 'weibaokaishishijian') {
                            state.formData.weibaokaishishijian = obj[o];
                            state.roisfalg.weibaokaishishijian = true;
                            continue;
                        }
                                                                                if (o == 'weibaojieshushijian') {
                            state.formData.weibaojieshushijian = obj[o];
                            state.roisfalg.weibaojieshushijian = true;
                            continue;
                        }
                                                                                if (o == 'fuzeren') {
                            state.formData.fuzeren = obj[o];
                            state.roisfalg.fuzeren = true;
                            continue;
                        }
                                                                                if (o == 'lianxifangshi') {
                            state.formData.lianxifangshi = obj[o];
                            state.roisfalg.lianxifangshi = true;
                            continue;
                        }
                                                                                if (o == 'userid') {
                            state.formData.userid = obj[o];
                            state.roisfalg.userid = true;
                            continue;
                        }
                                                }


        }
    }

    const emit = defineEmits(['refresh']);

    const close=()=>{
        state.visible=false;
    }

    function submitForm(){
        formRef.value?.validate((valid:boolean)=>{

            if(!valid) return;
            state.loadding=true;
            request({
                url:`weibaojihua/${!state.formData.id ? "save" : "update"}`,
                method:'post',
                data:state.formData
            }).then(({data})=>{
                notify("操作成功",{type:'success'});
            state.loadding=false;
            close();
            emit("refresh");
        })



        })

    }

    defineExpose({
        open
    })


                    


                    


                    


                    


                    


                    


                    


                    


                    


                    


                    


        
</script>

<template>
    <el-dialog :title="`${title}`" v-model="visible"
               center draggable :before-close="close" width="1000px"
               :close-on-click-modal="false" destroy-on-close>
        <div v-loading="loadding">
            <el-form ref="formRef" :model="formData"
                     label-width="85px" label-right="right"
                     label-suffix=":" status-icon
            >
                                                                                                            
                        <el-form-item label="维保项目" prop="weibaoxiangmu" :rules="{required: true, message: '维保项目为必填项！', trigger: 'blur'}">
                            <el-input v-model="formData.weibaoxiangmu" maxlength="30" clearable show-word-limit placeholder="请输入维保项目" :readonly="roisfalg.weibaoxiangmu"/>
                        </el-form-item>
                                                                                                                        

                                                        
                        <el-form-item label="维保内容" prop="weibaoneirong" :rules="{required: true, message: '维保内容为必填项！', trigger: 'blur'}">
                            <el-input v-model="formData.weibaoneirong" maxlength="30" clearable show-word-limit placeholder="请输入维保内容" :readonly="roisfalg.weibaoneirong"/>
                        </el-form-item>
                                                                                                                        

                                                        
                        <el-form-item label="维保周期" prop="weibaozhouqi" :rules="{required: true, message: '维保周期为必填项！', trigger: 'blur'}">
                            <el-input v-model="formData.weibaozhouqi" maxlength="30" clearable show-word-limit placeholder="请输入维保周期" :readonly="roisfalg.weibaozhouqi"/>
                        </el-form-item>
                                                                                                                        

                                                        
                        <el-form-item label="维保地点" prop="weibaodidian" :rules="{required: true, message: '维保地点为必填项！', trigger: 'blur'}">
                            <el-input v-model="formData.weibaodidian" maxlength="30" clearable show-word-limit placeholder="请输入维保地点" :readonly="roisfalg.weibaodidian"/>
                        </el-form-item>
                                                                                                                        

                                                                                <el-form-item label="维保开始时间" prop="weibaokaishishijian"  :rules="{required: true, message: '维保开始时间为必填项', trigger: 'blur'}">

                            <el-date-picker
                                    v-model="formData.weibaokaishishijian"
                                    type="datetime"
                                    value-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="维保开始时间"
                            />


                        </el-form-item>
                                                                                <el-form-item label="维保结束时间" prop="weibaojieshushijian"  :rules="{required: true, message: '维保结束时间为必填项', trigger: 'blur'}">

                            <el-date-picker
                                    v-model="formData.weibaojieshushijian"
                                    type="datetime"
                                    value-format="YYYY-MM-DD HH:mm:ss"
                                    placeholder="维保结束时间"
                            />


                        </el-form-item>
                                                        
                        <el-form-item label="负责人" prop="fuzeren" :rules="{required: true, message: '负责人为必填项！', trigger: 'blur'}">
                            <el-input v-model="formData.fuzeren" maxlength="30" clearable show-word-limit placeholder="请输入负责人" :readonly="roisfalg.fuzeren"/>
                        </el-form-item>
                                                                                                                        

                                                        
                        <el-form-item label="联系方式" prop="lianxifangshi" :rules="{required: true, message: '联系方式为必填项！', trigger: 'blur'}">
                            <el-input v-model="formData.lianxifangshi" maxlength="30" clearable show-word-limit placeholder="请输入联系方式" :readonly="roisfalg.lianxifangshi"/>
                        </el-form-item>
                                                                                                                        

                                                                        


                
            </el-form>
            <el-row justify="center" class="mt10">
                <el-button @click="close">取 消</el-button>
                <el-button @click="submitForm" type="primary">保 存</el-button>
            </el-row>
        </div>
    </el-dialog>

            
            
            
            
            
            
            
            
            
            
            
    

</template>

<style lang="scss" scoped>


                                                                                                                                                                                                                                        .avatar-uploader{
        border:1px solid #e4e6e9
    }

    .avatar-uploader .el-upload {
        border: 1px dashed var(--el-border-color);
        border-radius: 6px;
        cursor: pointer;
        position: relative;
        overflow: hidden;
        transition: var(--el-transition-duration-fast);
    }

    .avatar-uploader .el-upload:hover {
        border-color: var(--el-color-primary);
    }

    .el-icon.avatar-uploader-icon {
        font-size: 28px;
        color: #8c939d;
        width: 178px;
        height: 178px;
        text-align: center;
    }
</style>
